//
// Created by 11510 on 2024/6/11.
//
#include <iostream>
using namespace std;

// 复数
class Complex{
private:
    int _real;
    int _image;

public:
    int getReal() const {
        return _real;
    }

    void setReal(int real) {
        _real = real;
    }

    int getImage() const {
        return _image;
    }

    void setImage(int image) {
        _image = image;
    }

public:
    Complex(int real, int image):_real(real), _image(image){}

    void print() const{
        cout << _real << " + " << _image << "i" << endl;
    }

};

/**
 * 采用普通函数重载运算符
 * 一般定义一个普通函数(operator+运算符)
 *
 * 一般不用这种方式，因为get系列的共有函数让私有的成员几乎完全失去了隐藏效果
 * @param lhs
 * @param rhs
 * @return
 */
Complex operator+(const Complex& lhs, const Complex &rhs){
    return Complex(lhs.getReal() + rhs.getReal(), lhs.getImage() + rhs.getImage());
}



void test0(){
    Complex cx1(1, 2);
    Complex cx2(3, 4);

    Complex cx3 = cx1 + cx2;
    cx3.print();
}


int main() {
    test0();
    return 0;
}